Lab Crossover Event

Daniel Fuller

11/02/2020

R: The Swiss Army Knife of Science

Why use R?

Why use R?

RStudio IDE

#

Packages/Libraries

Installing the package install.packages("tidyverse")

Loading the package library(tidyverse)

Packages/Libraries

data <- read_csv(“/The/Path/To/Your/File.csv”)

Doing simple things in R

## [1] 4
## [1] 8

Reading in some data

## Warning: Missing column names filled in: 'X21' [21], 'X22' [22],
## 'X23' [23], 'X24' [24], 'X25' [25], 'X26' [26]
## Parsed with column specification:
## cols(
##   .default = col_character(),
##   Region = col_double(),
##   Population = col_number(),
##   Census = col_double(),
##   `Election Year` = col_double(),
##   Sex = col_double(),
##   `ID Number` = col_logical(),
##   `Size of Council` = col_double(),
##   `Campaign Spending` = col_logical(),
##   X21 = col_logical(),
##   X22 = col_logical(),
##   X23 = col_logical(),
##   X24 = col_logical(),
##   X25 = col_logical(),
##   X26 = col_logical()
## )
## See spec(...) for full column specifications.
## Warning: 11 parsing failures.
##  row col expected actual                                                                            file
## 1185 Sex a double      . 'https://github.com/walkabillylab/lab_crossover_r/raw/master/nl_candidates.csv'
## 1628 Sex a double      . 'https://github.com/walkabillylab/lab_crossover_r/raw/master/nl_candidates.csv'
## 1807 Sex a double      . 'https://github.com/walkabillylab/lab_crossover_r/raw/master/nl_candidates.csv'
## 2878 Sex a double      . 'https://github.com/walkabillylab/lab_crossover_r/raw/master/nl_candidates.csv'
## 3222 Sex a double      . 'https://github.com/walkabillylab/lab_crossover_r/raw/master/nl_candidates.csv'
## .... ... ........ ...... ...............................................................................
## See problems(...) for more details.

Some quick descriptive statistics

## Warning: NAs introduced by coercion
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##     0.0     1.0    77.0   155.6   192.5  2034.0     548

Recoding a variable

## ── Attaching packages ────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.1     ✔ purrr   0.3.3
## ✔ tibble  2.1.3     ✔ dplyr   0.8.3
## ✔ tidyr   1.0.0     ✔ stringr 1.4.0
## ✔ ggplot2 3.2.1     ✔ forcats 0.4.0
## ── Conflicts ───────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()

Recoding a variable

## Warning: Removed 548 rows containing non-finite values (stat_boxplot).

The great R wars

Two similar but different methods for many common tasks

Where to find packages

Ocean Plastic Sciences

Political Sciences

Workflow Revolution